package com.simplesoftwares.client.library.appskeleton;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Label;

/**
 * Handels all the events corresponding to view transition
 * To Do: Empact of GWT Event bus and history managemnt is not understood.
 * 
 * @author Kamala
 *
 */
public class SkeletonEventHandling implements ClickHandler
{

	@Override
	public void onClick(ClickEvent event) 
	{
		
		
		/*
		 * Get the text of currently clicked label.Iterate the items array to find the clicked menuitem.
		 * Once found call its transition method to initiate the screen transition.
		 * 
		 */
		if(event.getSource() instanceof Label)
		{
			HasClickHandlers myLabel=  (HasClickHandlers) event.getSource();
			
			AppMemory mem=AppMemory.getAppMemory();
			for(int i=0;i<mem.items.size();i++)
			{
				Label temp=(Label)mem.items.get(i).getLabel();
				if(temp==myLabel)
				{
					mem.items.get(i).screenTransition(); //changes the screen
					break;
				}
			}
		}
	}
}
